package com.zc.basic.app.controller;

import com.zc.basic.app.service.PcmcUserService;
import com.zc.basic.domain.dto.UserDto;
import com.zc.basic.domain.pojo.PcmcUser;
import com.zc.basic.infra.mapper.UserDtoMapper;
import com.zc.commons.pojo.AuthenticatedUser;
import com.zc.commons.pojo.ResponseData;
import com.zc.commons.utils.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private PcmcUserService pcmcUserService;

    @Autowired
    private UserDtoMapper userDtoMapper;

    @GetMapping(value = "/all")
    public ResponseData<List<PcmcUser>> queryAllUser() {
        List<PcmcUser> list = pcmcUserService.list();
        return ResponseData.ok(list);
    }

    @GetMapping(value = "/info")
    public UserDto queryTokenUser() {
        AuthenticatedUser currentUser = UserUtil.getCurrentUser();
        return userDtoMapper.queryInfoByCode(currentUser.getUserCode());
    }


}
